import tornado.web
import session
import ujson

from aip import AipFace
""" 你的 APPID AK SK """
APP_ID = '16215391'
API_KEY = 'MH3GgGXo98eMiErdZ4nGVyHT'
SECRET_KEY = 'VI6LzVtlYzuFEY1NfHDQR5R2zyNB1OG6'


class ResponseCode:
    """成功状态码  """
    SUCCESS = {'status': 1, 'msg': "成功"}

    """参数错误：10001 - 19999  """
    PARAM_IS_INVALID = {'status': 10001, 'msg': "参数无效"}
    PARAM_NOT_COMPLETE = {'status': 10002, 'msg': "参数缺失"}
    PARAM_TYPE_BIND_ERROR = {'status': 10003, 'msg': "参数类型错误"}

    """用户错误：20001 - 29999  """
    USER_NOT_LOGGED_IN = {'status': 20001, 'msg': "用户未登录"}
    USER_LOGIN_ERROR = {'status': 20002, 'msg': "账号不存在或密码错误"}
    USER_NOT_EXIST = {'status': 20003, 'msg': "用户不存在"}
    USER_HAS_EXISTED = {'status': 20004, 'msg': "用户已存在"}
    USER_FACE_ERROR = {'status': 20005, 'msg': "照片错误,请确认是否为清晰正面照"}
    USER_NOT_UPLOAD_FACE = {'status': 20006, 'msg': "用户未正常注册"}

    COURSE_NOT_EXIST = {'status': 20007, 'msg': "课程不存在"}
    """数据库错误：30001 - 39999  """

    """系统错误：40001 - 49999  """
    SYSTEM_BUSY_ERROR = {'status': 40001, 'msg': "系统繁忙，请稍后重试"}

    """数据错误：50001 - 599999  """
    RESULE_DATA_NONE = {'status': 50001, 'msg': "数据未找到"}
    DATA_IS_WRONG = {'status': 50002, 'msg': "数据有误"}
    DATA_ALREADY_EXISTED = {'status': 50003, 'msg': "数据已存在"}

    """接口错误：60001 - 69999  """
    INTERFACE_INNER_INVOKE_ERROR = {'status': 60001, 'msg': "内部系统接口调用异常"}
    INTERFACE_OUTTER_INVOKE_ERROR = {'status': 60002, 'msg': "外部系统接口调用异常"}
    INTERFACE_FORBID_VISIT = {'status': 60003, 'msg': "该接口禁止访问"}
    INTERFACE_ADDRESS_INVALID = {'status': 60004, 'msg': "接口地址无效"}
    INTERFACE_REQUEST_TIMEOUT = {'status': 60005, 'msg': "接口请求超时"}
    INTERFACE_EXCEED_LOAD = {'status': 60006, 'msg': "接口负载过高"}

    """权限错误：70001 - 79999  """
    PERMISSION_NO_ACCESS = {'status': 70001, 'msg': "无访问权限"}

    """其他错误：80001 - 89999"""
    YZM_IS_WRONG = {'status': 80001, 'msg': "验证码出错"}


class BaseHandler(tornado.web.RequestHandler):
    def __init__(self, *argc, **argkw):
        super(BaseHandler, self).__init__(*argc, **argkw)
        # 此处实例化Session, 但是具有同一个session_manager
        self.session = session.Session(self.application.session_manager, self)
        self.response_code = ResponseCode
        self.face_client = AipFace(APP_ID, API_KEY, SECRET_KEY)
